package cn.nubia.admin.common.http;



import cn.nubia.admin.common.springmvc.WebContext;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * User: wangj
 * Date: 13-11-6
 * Time: 上午9:34
 */
public class InitFilter  implements Filter {

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        WebContext.setRequest(httpRequest);
        WebContext.setResponse((HttpServletResponse) response);
        WebContext.getResponse().setContentType("text/html;charset=UTF-8");

        try {
            filterChain.doFilter(request ,response);
        } catch (Exception e) {
            throw e;
        }finally{
            WebContext.remove();
        }
    }

    public void init(FilterConfig arg0) throws ServletException {
    }
}
